<?php
 
include_once("./configure/configure.php");						//--> global var
include_once("./admin/tools/smarty/libs/Smarty.class.php");		//--> out template
include_once("utils/FileUtils.php");				//--> file utils

include_once("impl/CategoryImpl.php");
include_once("impl/ContentImpl.php");
include_once("impl/TagImpl.php");

include_once("includeSmarty.php");


$id 	= $_POST['id'];
$page 	= $_POST['page'];
$order 	= $_POST['order'];


if(empty($id)){
	$location = HOME_URL_HTTP;
	
	header("Location: $location");
	exit;
}


$cacheId = $id . '_' . $page;

/*----- out html -----*/
$SUB_DIR	= FileUtils::getDirByString($id) . '/';

$smarty->compile_dir  	= COMPILE_DIR . '/cat/' . $SUB_DIR;
$smarty->cache_dir  	= CACHE_DIR . '/cat/' . $SUB_DIR;

if(!$smarty->isCached('category.html', $cacheId, $cacheId)){	
	$oCatImpl 		= new CategoryImpl(DB_TAG_MM);
	$tagImpl		= new TagImpl(DB_TAG_MM);
	$oContImpl 		= new ContentImpl(DB_TAG_MM);
	
	$oCategory 	= $oCatImpl->getById($id);
	if(!is_object($oCategory)){
		$location = HOME_URL_HTTP;
		
		header("Location: $location");
		exit;
	}
	
	$catIds 	= $oCatImpl->getLeafIdsStr($oCategory->id, true);
	$oContents	= $oContImpl->getAllCategories($catIds, $page, 18);
	
	
	$oCats 		= $oCatImpl->getLeaf();
	
	$oTags		= $tagImpl->getCategoryTags($oCategory->id, 1, 15);
	if(count($oTags) == 0)
		$oTags	= $tagImpl->getTags(1, 15);
	
	$smarty->assign('oContents', $oContents);
	
	
	$smarty->assign('oCat', $oCategory);
	$smarty->assign('oCats', $oCats);
	$smarty->assign('oTags', $oTags);
	
	
	$smarty->assign('id', $id);
	$smarty->assign('order', $order);
	
	$smarty->assign('pageList', $oContImpl->getPageList(9));
	$smarty->assign('nextPage', $oContImpl->getNextPage());
	$smarty->assign('prePage', $oContImpl->getPrePage());
	$smarty->assign('pageCount', $oContImpl->getPageCount());
	$smarty->assign('page', $oContImpl->getPage());
	
}

$smarty->assign('HOME_URL', HOME_URL);
$smarty->assign('HOME_URL_HTTP', HOME_URL_HTTP);
$smarty->assign('DEBUG', DEBUG);


$smarty->display('category.html', $cacheId, $cacheId);
?>
